import Vue from 'vue'
import App from './App.vue'
import ZkTable from 'vue-table-with-tree-grid'
import VueQuillEditor from 'vue-quill-editor'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
// 导入全部的element-ui组件
// import ElementUI from 'element-ui'
// Vue.use(ElementUI)

// 按需导入
import './plugins/element'
import 'element-ui/lib/theme-chalk/index.css'
import router from './router'
import store from './store'
// 字体图标可以
import '@/assets/fontIco/iconfont.css'

// 全局样式
import '@/assets/css/glob.less'

import jsCookie from 'js-cookie'
Vue.prototype.$jsCookie = jsCookie

// 简单配置
NProgress.inc(0.2)
NProgress.configure({ easing: 'ease', speed: 500, showSpinner: false })

router.beforeEach((to, from, next) => {
  const tookenStr = jsCookie.get('token')
  if (!tookenStr) {
    if (to.name === 'login') {
      next()
    } else {
      next('/login')
    }
  } else {
    next()
  }
  if (to.path === '/welcome') {
    sessionStorage.removeItem('defaultActive')
  }
  NProgress.start()
  next()
})

router.afterEach(() => {
  NProgress.done()
})

Vue.use(ZkTable)
Vue.config.productionTip = false

Vue.use(VueQuillEditor)

Vue.filter('dft', (str) => {
  /**
   * 正常获取的时间戳应该是13位(毫秒)
   * 但是这里我们得到只有10位(秒)
   * 所以需要*1000转换成毫秒
   */
  const dataTime = new Date(str * 1000)
  const YYYY = dataTime.getFullYear()
  const MM = (dataTime.getMonth() + 1 + '').padStart(2, '0')
  const DD = (dataTime.getDay() + '').padStart(2, '0')
  const HH = dataTime.getHours()
  const mm = dataTime.getMinutes()
  const ss = dataTime.getSeconds()
  return `${YYYY}-${MM}-${DD} ${HH}:${mm}:${ss}`
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
